package main

import (
	"fmt"
	"sort"
)

//练习对学生成绩降序排序

type Student struct {
	Name  string
	Score int32
}
type StudentSlice []Student

func (stus StudentSlice) Swap(i, j int) {
	stus[i], stus[j] = stus[j], stus[i]
}

func (stus StudentSlice) Len() int {
	return len(stus)
}

//大于则倒序
func (stus StudentSlice) Less(i, j int) bool {
	return stus[i].Score > stus[j].Score
}

func main() {
	var stus StudentSlice
	for i := 1; i <= 10; i++ {
		stu := Student{
			Name:  fmt.Sprintf("学生%v", i),
			Score: int32(i * 10),
		}
		stus = append(stus, stu)
	}
	sort.Sort(stus)
	fmt.Println(stus)

}
